package xiaoqi.springboot.boot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import xiaoqi.springboot.boot.cn.iocoder.springboot.lab64.userservice.api.*;

@RestController
@RequestMapping("/demo")
public class DemoController {
    @Autowired
    private UserServiceGrpc.UserServiceBlockingStub userService;


    @GetMapping("/get")
    public String get(@RequestParam("id") Integer id) {
        UserGetRequest request = UserGetRequest.newBuilder().setId(id).build();
        UserGetResponse response = userService.get(request);
        return response.getName();
    }

    @GetMapping("/create")
    public Integer create(@RequestParam("name") String name, @RequestParam("gender") Integer gender) {
        UserCreateRequest request = UserCreateRequest.newBuilder().setName(name).setGender(gender).build();
        UserCreateResponse response = userService.create(request);
        return response.getId();
    }
}
